<?php

/**
 * Description of WebPhoto
 *
 * @author Marco Mounzer
 * @file WebPhoto
 * @copyright 2013
 * $Id: WebPhoto $
 */
require_once 'Database.php';
require_once 'WebCar.php';

class WebPhoto extends ObjectForm {

    public $Id;
    public $name;
    public $extension;
    public $car_id;

    public function __construct() {
        $this->Id = 0;
        //$this->car = new WebCar();
    }

    protected $formFields = array('Id' => ObjectForm::TYPE_HIDDEN,
        //'car' => ObjectForm::TYPE_SELECT,
        'name' => ObjectForm::TYPE_HIDDEN,
        'extension' => ObjectForm::TYPE_HIDDEN,
    );

    //protected $formFieldsDescriptors = array('car' => 'modello');

    public function delete() {
        $uploaddir = $_SERVER["DOCUMENT_ROOT"] . "/images/cars/";
        $filename = $uploaddir . $this->Id . '.' . $this->extension;

        if (Database::DeleteObject($this)) {
            if (file_exists($filename))
                unlink($filename);
        }
    }
}